package com.fyl.pattern.prototype.test2;


import java.io.*;

/**
 * 引用类型浅克隆
 */
public class Client {
    public static void main(String[] args) throws CloneNotSupportedException, IOException, ClassNotFoundException {
        //1.创建原型对象
        Citation citation = new Citation();
        Student student = new Student();
        student.setName("张三");
        citation.setStudent(student);

        //把citation写到文件中
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("C:\\Users\\13037\\Desktop\\b.txt"));
        //写对象
        oos.writeObject(citation);
        //释放资源
        oos.close();



        //2.克隆对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\Users\\13037\\Desktop\\b.txt"));
        //读取对象
       Citation clone = (Citation) ois.readObject();

        //释放资源
        ois.close();
        System.out.println("1111111");
        clone.show();
        clone.getStudent().setName("李四");
        System.out.println("2222222");
        citation.show();
        clone.show();
    }
}
